<?php
$oReq = &App::getRequest();
$sModule = $oReq->get('module', 'gallery');
$sType = $oReq->get('type','jpg');
$sFile = $oReq->get('file','');

$aDataList = array(
		'gallery'	=> array(App::getParam('gallery.pic.path'), 'image/'.$sType, 'bImageSecurity'),
		'groups'	=> array(App::getParam('groups.pic.path'), 'image/'.$sType, 'bImageSecurity'),
		'music'		=> array(App::getParam('music.path'), 'audio/'.$sType, 'bSongSecurity'),
		'video'		=> array(App::getParam('video.path'), 'video/'.$sType, 'bVideoSecurity'),
	);

if ($sModule == 'gallery-thumb')
{
	$aDataList['gallery'] = array(App::getParam('gallery.pic.path') . 'thumb/', 'image/'.$sType, 'bImageSecurity');
	$sModule = 'gallery';
}

if ($sModule == 'groups-thumb')
{
	$aDataList['groups'] = array(App::getParam('groups.pic.path') . 'thumb/', 'image/'.$sType, 'bImageSecurity');
	$sModule = 'groups';
}

$bAccess = FALSE;

if(isset($aDataList[$sModule]))
{
	$sDataUrl = $aDataList[$sModule][0] . $sFile.'.'.$sType;

	if(App::getParam($aDataList[$sModule][2]))
		$bAccess = App::getAccessForContent($sModule,$sFile,$sType);
	else
		$bAccess = TRUE;
		
	if($bAccess)
	{
		if(file_exists($sDataUrl))
		{
			ob_clean();
			header('Content-Type: '.$aDataList[$sModule][1]);
			echo file_get_contents($sDataUrl);
		}
	}
	else
	{
		$sText = "Access Denied";
		switch($sModule)
		{
			case 'gallery':
			case 'groups':
				$nW = 140;
		        $nH = 30;
		        $nLeft = 5;
		        $nTop = 5;
				$hImg = imageCreate($nW, $nH);
			    $nBgColor  = imageColorAllocate($hImg, 0, 0, 0);
		        $nTxtColor = imageColorAllocate($hImg, 255, 255, 255);
		        imageString($hImg, 5, $nLeft, $nTop,  $sText, $nTxtColor) or die();
		        ob_clean();
		        header('Content-Type: image/jpeg');
		        imagejpeg($hImg);				
				break;
			default:
				echo $sText;
				break;
		}
	}
}

exit(1);
?>